package com.pactera.asmp.server.controller;

import com.pactera.asmp.server.common.bug.impl.JiraBugHandlerImpl;
import com.pactera.asmp.server.common.constants.ResultCode;
import com.pactera.asmp.server.common.threadpool.task.PostTraceTask;
import com.pactera.asmp.server.entity.ProjectProductionConfig;
import com.pactera.asmp.server.entity.ResponseResult;
import com.pactera.asmp.server.entity.TestReportJiraDTO;
import com.pactera.asmp.server.entity.TestReportJiraEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * <p>Class: com.pactera.asmp.server.controller.IndexController</p>
 * <p>Description: </p>
 * <pre>
 *
 * </pre>
 *
 * @author lv zhiqiang
 * @date 2019/7/24/10:43
 */
@RestController
@RequestMapping("/")
public class IndexController {
    private static final Logger logger = LoggerFactory
            .getLogger(IndexController.class);
    @Autowired
    private JiraBugHandlerImpl jiraBugHandler;

    /**
     * @api {get} /index?testInfo
     * @apiDescription 首页测试接口
     * @apiName index
     * @apiParam {String} testInfo 测试信息
     * @apiParamExample {json} Request-Example:
     * {
     * "testInfo":"我们成功收到测试信息"
     * <p>
     * }
     * @apiGroup index
     * @apiError index err info   The <code>testInfo</code>
     * @apiSampleRequest /index
     */
    @GetMapping("/index1")
    public String index(@RequestParam(value = "testInfo", required = false) String testInfo) {
        logger.info("-------------index page ------------{}", testInfo);
        test();
        return testInfo;
    }


    @GetMapping("/toLogin")
    public ResponseResult index() {
        logger.info("-------------index page ------------ toLogin ----->");
        TestReportJiraDTO testReportJiraDTO = new TestReportJiraDTO();
        TestReportJiraEntity testReportJiraEntity = new TestReportJiraEntity();
        testReportJiraDTO.setMonkeyExceptionInfos(Arrays.asList(testReportJiraEntity));
        ProjectProductionConfig projectProductionConfig = new ProjectProductionConfig();
        projectProductionConfig.setBugSubmitTo("JIRA");
        projectProductionConfig.setBugUrl("https://jira-shzj.auto-link.com.cn");
        projectProductionConfig.setBugAccount("liuhui_zd");
        projectProductionConfig.setBugPassword("e7pM6YZDyi");
        projectProductionConfig.setBugProjectId("12008");
        projectProductionConfig.setPriority("5");
        jiraBugHandler.handleBugForMonkey("aa","bb",testReportJiraEntity,testReportJiraDTO, projectProductionConfig);
        return new ResponseResult(ResultCode.PERMISSION_EXPIRE);
    }

    private static void test() {
        PostTraceTask task = new PostTraceTask("TaskName 100", 0);
        task.executeWorkTask();
    }

    /**
     * @api {get} /info
     * @apiDescription 获取ASMP系统介绍
     * @apiName getServerInfo
     * @apiParamExample {json} Request-Example:
     * {
     * "result":"getServerInfo",
     * <p>
     * }
     * @apiGroup getServerInfo
     * @apiError getServerInfo error
     * @apiSampleRequest /info
     */
    @GetMapping("/info")
    public String getServerInfo() {
        return "ASMP Server By lzq";
    }


    @GetMapping("/kickout")
    public ResponseResult kickout() {
        return new ResponseResult(ResultCode.USER_STATUE_KIKOFF);
    }

}
